<html class="x-admin-sm" lang="ch">
  <head>
      <meta charset="UTF-8">
      <title>客户管理</title>
      <meta name="renderer" content="webkit">
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
      <script type="text/javascript" src="js/jquery-3.4.0.js"></script>
      <link rel="stylesheet" href="css/font.css">
      <link rel="stylesheet" href="css/xadmin.css">
      <link rel="stylesheet" href="css/bootstrap.min.css">

      <script type="text/javascript" src="lib/layui/layui.js" charset="utf-8"></script>
      <script type="text/javascript" src="js/address.js"></script>
      <script type="text/javascript" src="js/xadmin.js"></script>
      <script type="text/javascript" src="js/cookie.js"></script>
      <script type="text/javascript" src="js/bootstrap.min.js"></script>
      <script type="text/javascript" src="js/bootstrap-table.js"></script>

  </head>
  <script>
      $(function(){
          $("#submit").click(function () {
              var str=  address + "customer/list";
              var name = $("#name").val();
              var phone = $("#phone").val();
              var regionCode = $("#regionCode").val();
              var bool = false;
              if (name !== '' && name !== null) {
                  str = str + "?name=" + name;
                  bool = true;
              }
              if (bool === true) {
                  bool = false;
                  if (phone !== '' && phone !== null) {
                      str = str + "&phone=" + phone;
                      bool = true;
                  }
              } else {
                  if (phone !== '' && phone !== null) {
                      str = str + "?phone=" + phone;
                      bool = true;
                  }
              }
              if (bool === true) {
                  bool = false;
                  if (regionCode !== '' && regionCode !== null) {
                      str = str + "&regionCode=" + regionCode;
                      bool = true;
                  }
              } else {
                  if (regionCode !== '' && regionCode !== null) {
                      str = str + "?regionCode=" + regionCode;
                      bool = true;
                  }
              }
              $.ajax({
                  url:str,
                  type:"GET",
                  dataType:'JSON',
                  contentType : "application/json; charset=utf-8",
                  success:function(data){
                      var tableData;
                      var customerList = data.customerList;
                      $("#numspan").text("显示数据："+(customerList.length).toString()+"条");
                      for(var i=0;i<customerList.length;i++){
                          if (customerList[i].department === undefined) {
                              customerList[i].department = '';
                          }
                          // var str="<td class='td-manage'>"+
                          //     '<a title="编辑"  href="javascript:;"  onclick="x_admin_show( \'编辑\',\'customer-edit.html?Data='+customerList[i].id+'\',600,400)">'+
                          //     "<i class=\"layui-icon\">&#xe642;</i>" +
                          //     "</a>" +
                          //     '<a title="删除" href="javascript:;" onclick="customer_del(this,'+customerList[i].id+')">'+
                          //     "<i class='layui-icon'>&#xe640;</i> " +
                          //     "</a> "+
                          //     "</td>";
                              tableData+="<tr> " +
                                  "<td>"+customerList[i].id +"</td> " +
                                  "<td>"+customerList[i].name +"</td>" +
                                  "<td>"+customerList[i].telCode +"</td>" +
                                  "<td>"+customerList[i].department +" </td>" +
                                  "<td>"+customerList[i].regionCode +"</td>" +
                                  "<td>"+customerList[i].address +"</td>" +
                                  "<td>"+customerList[i].postCode +"</td> " +str+
                              "</tr>";
                      }
                      $("#firsttbody").html(tableData);

                  },
                  error:function(){
                      alert("error");
                  }
              });
          });
          $("#table").bootstrapTable({
              search:true,
             columns:[{
                 field:'id',
                 title:'ID'
             },{
                 field:'name',
                 title:'姓名'
             },{
                 field:'telCode',
                 title:'电话号码'
             },{
                 field:'department',
                 title:'部门'
             },{
                 field:'regionCode',
                 title:'地区编码'
             },{
                 field:'address',
                 title:'地址'
             },{
                 field:'postCode',
                 title:'邮政编码'
             },]
          });
      });
  </script>
  
  <body>
  <div class="x-nav">
      <span class="layui-breadcrumb">
          <a href="">客户列表</a>
      </span>
      <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
          <i class="layui-icon" style="line-height:30px">刷新</i>
      </a>
  </div>
  <div class="x-body">
      <div class="layui-row">

          <form class="layui-form layui-col-md12 x-so" method="#">
              <div class="layui-inline" style="margin-left: 430px">
                  <input id="name" class="layui-input" type="text" name="name" placeholder="请输入姓名" autocomplete="off" value="">
                  <input id="phone" class="layui-input" type="text" name="phone" placeholder="请输入电话号码" autocomplete="off" value="">
                  <input id="regionCode" class="layui-input" type="text" name="regionCode" placeholder="请输入地区编码" autocomplete="off" value="">
                  <button class="layui-btn" id="submit" type="button"><i class="layui-icon">&#xe615;</i></button>
              </div>
          </form>

      </div>

      <xblock>
          <!--<button class="layui-btn" onclick="x_admin_show('添加用户','./customer-add.html',600,400)"><i class="layui-icon"></i>添加</button>-->
          <span class="x-right" id="numspan" style="line-height:40px" type="text">显示数据：0条</span>
      </xblock>

      <table class="table table-bordered" id="table" data-pagination="true" data-side-pagination="client" data-page-size="4">
          <!--<thead>-->
              <!--<tr>-->
                  <!--<th>ID</th>-->
                  <!--<th>姓名</th>-->
                  <!--<th>手机</th>-->
                  <!--<th>部门</th>-->
                  <!--<th>地区编码</th>-->
                  <!--<th>地址</th>-->
                  <!--<th>邮政编码</th>-->
              <!--</tr>-->
          <!--</thead>-->

          <tbody id="firsttbody"></tbody>

      </table>

      <!--<div class="page">-->
          <!--<div>-->
              <!--<a class="prev">&lt;&lt;</a>-->
              <!--<a class="num">1</a>-->
              <!--<a class="next">&gt;&gt;</a>-->
          <!--</div>-->
      <!--</div>-->

  </div>
      <script>
      /*用户-删除*/
      function customer_del(obj,id){
          layer.confirm('确认要删除吗？',function(){
              //发异步删除数据
              var str= address + "customer/delete/" + id;
              $.ajax({
                  url:str,
                  type:"GET",
                  dataType:'JSON',
                  contentType : "application/json; charset=utf-8",
                  success:function(data){
                      layer.msg('已删除!',{icon:1,time:1000});
                  },
                  error:function(){
                      alert("error");
                  }
              });
              $(obj).parents("tr").remove();
              layer.msg('已删除!',{icon:1,time:1000});
          });
      }
      </script>
  </body>
</html>